﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using static YunRuiFarm.Models.DatabaseModels;

namespace YunRuiFarm.Filters
{
    public class NoPermissionRequiredAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
        }
    }
    public class PermissionRequiredAttribute : ActionFilterAttribute
    {

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Any())
            {
                string tempController = filterContext.RouteData.Values["controller"].ToString();
                if (tempController == "YunRuiFarmAPI")
                {
                    String tempToken = filterContext.HttpContext.Request.Cookies["token"].Value;
                    if (tempToken == null)
                    {
                        HttpContext.Current.Response.Write("<script>alert('请先登录');</script>");
                    }
                }
            }
        }
    }
}
